//
//  TakeDrugReminderViewController.m
//  安好
//
//  Created by lianchuang on 14-11-19.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "TakeDrugReminderViewController.h"

//
#import "LoginViewController.h"

//展示药品提醒页面
#import "ShowDrugDetialViewController.h"
//添加药品提醒页面
#import "AddDrugReminderViewController.h"
//家人详情展示页面
#import "ShowMyFamilyDetialViewController.h"
//家人病历列表页面
#import "FamilyMedicalrecordViewController.h"
//从我的家人蜂窝显示家人过来--此时要显示“病历”
#import "MyFamilyViewController.h"
//从用药提醒家人列表页面过来
#import "TakeDrugsViewController.h"

#define IPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)

@interface TakeDrugReminderViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)NSString * headerStr;

@end

@implementation TakeDrugReminderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self makeNavBarView];
    [self loadData];
    [self makeTableView];
    
//---------------------------
    //本地推送闹钟提醒点击跳到这个页面
    // 通知  当得到消息的时候 把页面返回  返回的页面完成后才可以支持跳转
    [[NSNotificationCenter defaultCenter] addObserverForName:@"yongyao" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
        MyNSLog("***%@", self.navigationController.viewControllers);
        
        if (self.navigationController.viewControllers.count >= 1&&[[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-1] isKindOfClass:[ShowDrugDetialViewController class]]) {
        }else{
        
            [self dismissViewControllerAnimated:YES completion:^{
            }];
            [self.navigationController popViewControllerAnimated:YES];
        }
        [[NSNotificationCenter defaultCenter] postNotificationName:@"DisMissView" object:nil];
        
        [self performSelector:@selector(presentDuihuaView) withObject:nil afterDelay:0.5];
    }];

}
-(void)presentDuihuaView
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"yongyao1" object:nil];
}
//每次返回来的时候都网络请求刷新数据
-(void)viewWillAppear:(BOOL)animated
{
    [self AFNetRequestForFamilyDrugReminderDetial];
}

#pragma mark - 设置导航条
-(void)makeNavBarView
{
    self.navigationItem.title = self.navBarTitle;
    //贴图
    UIBarButtonItem *backBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backBtnClicked)];
    backBtnImg.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = backBtnImg;
}
//“返回”
-(void)backBtnClicked
{
    if (self.isPresent == YES) {
        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    }else
    {
        [self.navigationController popViewControllerAnimated:YES];
    }

}

#pragma mark - 加载数据
-(void)loadData
{
    self.drugReminderArray = [NSMutableArray arrayWithCapacity:0];
    self.sectionDataArray = [NSMutableArray arrayWithCapacity:0];
    if (self.drugReminderArray.count == 0) {
        [self.sectionDataArray addObject:@"添加用药提醒"];
    }
    
    MyNSLog("%@", self.peopleDic);
    self.headerStr = self.peopleDic[@"avatar"];
    
    
    [self AFNetRequestForFamilyDrugReminderDetial];
    
}
#pragma mark - AFNet-网络请求获取家人用药提醒详情
-(void)AFNetRequestForFamilyDrugReminderDetial
{
    //先判断是否是自己 如果是自己的话把数据从本地取出来--即使网络失败也不会对自己的情况发生影响
    if ([self.peopleDic[@"uid"] intValue] == [self.peopleDic[@"fid"] intValue]) {
        NSUserDefaults * myDrugCount = [NSUserDefaults standardUserDefaults];
        NSArray * myDrugArray = [myDrugCount objectForKey:[NSString stringWithFormat:@"MyDrugReminder%@",self.peopleDic[@"uid"]]];
        
        [self.drugReminderArray removeAllObjects];
        for (NSDictionary * dic in myDrugArray) {
            FamilyDrugDetialModal * modal = [[FamilyDrugDetialModal alloc] initWithDic:dic];
            modal.reminderId = dic[@"id"];
            [self.drugReminderArray addObject:modal];
        }
        [self.sectionDataArray removeAllObjects];
        for (int i = 0; i < self.drugReminderArray.count; i++) {
            [self.sectionDataArray addObject:self.drugReminderArray[i]];
        }
        [self.sectionDataArray addObject:@"添加用药提醒"];
        [self.tableView reloadData];
    }
    
    [self showActionView];
    NSString *postURL = [NSString stringWithFormat:@"%@user/drug/",kBaseURL];
    NSDictionary * parameters = @{@"platform":kPlatform,@"version":kVersion,@"uid":self.peopleDic[@"uid"],@"fid":self.peopleDic[@"fid"]};
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:postURL parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {

        [self hiddenActionView];
        MyNSLog("成功");
        NSNumber * statusNum = [responseObject objectForKey:@"status"];
        NSNumberFormatter * numberFormatter = [[NSNumberFormatter alloc] init];
        NSString * statusString = [numberFormatter stringFromNumber:statusNum];
        if ([statusString isEqualToString:@"0"]) {
            MyNSLog("-*-*- %@:%@",self.peopleDic[@"username"], [responseObject objectForKey:@"msg"]);
            [self.sectionDataArray removeAllObjects];
             [self.sectionDataArray addObject:@"添加用药提醒"];
            [self.tableView reloadData];
            
        }else
        {
            //如果是我自己的话就要把自己的信息刷新本地数据
            if ([self.peopleDic[@"uid"] intValue] == [self.peopleDic[@"fid"] intValue]) {
                NSUserDefaults * myDrugCount = [NSUserDefaults standardUserDefaults];
                [myDrugCount setObject:responseObject[@"data"] forKey:[NSString stringWithFormat:@"MyDrugReminder%@",self.peopleDic[@"uid"]]];
                [myDrugCount synchronize];
            }
            
            NSArray * data = responseObject[@"data"];
            [self.drugReminderArray removeAllObjects];
            for (NSDictionary * dic in data) {
                FamilyDrugDetialModal * modal = [[FamilyDrugDetialModal alloc] initWithDic:dic];
                modal.reminderId = dic[@"id"];
                [self.drugReminderArray addObject:modal];
            }
            [self.sectionDataArray removeAllObjects];
            for (int i = 0; i < self.drugReminderArray.count; i++) {
                [self.sectionDataArray addObject:self.drugReminderArray[i]];
            }
            [self.sectionDataArray addObject:@"添加用药提醒"];
            
            [self.tableView reloadData];
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        MyNSLog("失败");
        [self hiddenActionView];
    }];

}

#pragma mark - 记载tableView
-(void)makeTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-iOS7TopMargin) style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = [ClassMethodsViewController colorWithHexString:BACK_BACKGROUNDCOLOR_16];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //隐藏横向和竖向的滑条
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    [self.tableView setSeparatorColor:[UIColor colorWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:1.0]];


}
#pragma mark - tableView的代理方法
//设置段数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if ([self.MedicalRecord isEqualToString:@"病历"]) {
        return 3;
    }
    if([self.MedicalRecord isEqualToString:@"没有病历"]){
        return 2;
    }
    return 0;
    
}
//设置每段的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([self.MedicalRecord isEqualToString:@"病历"])  {
        if (section == 2){
            return self.sectionDataArray.count;
        }else{
            return 1;
        }
    }
    if( [self.MedicalRecord isEqualToString:@"没有病历"]){
        if (section == 0){
            return 1;
        }else{
            return self.sectionDataArray.count;
        }
    }
    return 0;

}
//段头
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    CGFloat viewHeight = 30;
    CGFloat viewLeft = 15;
    CGFloat textfont = 13;
    if (IPhone6Plus) {
        viewHeight = 40;
        viewLeft = 20;
        textfont = 15;
    }
    if ([self.MedicalRecord isEqualToString:@"病历"]) {
        if (section == 2) {
            UIView * secondSectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, viewHeight)];
            UILabel * drugReminderLable = [[UILabel alloc] initWithFrame:CGRectMake(viewLeft,0 ,kScreenWidth-viewLeft,viewHeight)];
            drugReminderLable.text = @"用药提醒";
            drugReminderLable.font = [UIFont systemFontOfSize:textfont];
            drugReminderLable.textColor = [UIColor grayColor];
            drugReminderLable.textAlignment = NSTextAlignmentLeft;
            [secondSectionHeaderView addSubview:drugReminderLable];
            return secondSectionHeaderView;
        }
        return nil;
    }
    if([self.MedicalRecord isEqualToString:@"没有病历"]){
        if (section == 1) {
            UIView * secondSectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, viewHeight)];
            UILabel * drugReminderLable = [[UILabel alloc] initWithFrame:CGRectMake(viewLeft,0 , kScreenWidth-viewLeft,viewHeight)];
            drugReminderLable.text = @"用药提醒";
            drugReminderLable.font = [UIFont systemFontOfSize:textfont];
            drugReminderLable.textColor = [UIColor grayColor];
            drugReminderLable.textAlignment = NSTextAlignmentLeft;
            [secondSectionHeaderView addSubview:drugReminderLable];
            return secondSectionHeaderView;
            
        }
        return nil;
    }
    return nil;

}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if ([self.MedicalRecord isEqualToString:@"病历"]) {
        if (section == 2) {
            if (IPhone6Plus) {
                return 40;
            }else{
                return 30;
            }
        }else
        {
            if (IPhone6Plus) {
                return 12;
            }else{
                return 10;
            }
        }
    }
    if( [self.MedicalRecord isEqualToString:@"没有病历"]){
        if (section == 0) {
            if (IPhone6Plus) {
                return 12;
            }else{
                return 10;
            }
        }else
        {
            if (IPhone6Plus) {
                return 40;
            }else{
                return 30;
            }
        }
    }else{
        return 0.01;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (IPhone6Plus) {
            return 78;
        }else{
            return 64;
        }
    }else
    {
        if (IPhone6Plus) {
            return 53;
        }else{
            return 44;
        }
    }
}
#pragma mark - 加载cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //关系字典
    NSDictionary * typeDic = @{@"1":@"祖父母",@"2":@"父母",@"3":@"其他平辈",@"4":@"子女",@"5":@"孙辈",@"6":@"爱人",@"7":@"我"};

    if ([self.MedicalRecord isEqualToString:@"病历"]) {
        //第一段：头像+名字+关系
        if (indexPath.section == 0)
        {
            FamilyInfoFirstSectionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"First"];
            if (cell == nil) {
                if (IPhone6Plus) {
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyInfoFirstSectionCell" owner:self options:nil] lastObject];
                }else{
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyInfoFirstSectionCell" owner:self options:nil] firstObject];
                }
            }
            cell.familyHeaderImgView.clipsToBounds = YES;
            cell.familyHeaderImgView.layer.cornerRadius = 3;
            NSString * fid = [NSString stringWithFormat:@"%@",self.peopleDic[@"fid"]];
            NSString * uid = [NSString stringWithFormat:@"%@",self.peopleDic[@"uid"]];
            cell.jumpImgView.right = kScreenWidth-15;
            if (IPhone6Plus) {
                cell.jumpImgView.right = kScreenWidth-20;
            }
            
            
            //如果是自己的话
            if ([fid isEqualToString:uid])//uid和fid一样就是“我”
            {
                //头像
                UIImage * userImg = [[UserManager shareInstance] getUserImage];
                if (userImg) {
                    [cell.familyHeaderImgView setImage:userImg];
                }else{
                    [cell.familyHeaderImgView setImage:[UIImage imageNamed:@"默认头像.png"]];
                }

                //名字+关系
                if ([self.peopleDic[@"realname"] length] !=0)
                {
                    cell.familyNameLable.text =[NSString stringWithFormat:@"我(%@)",self.peopleDic[@"realname"]];
                }
                else{
                    cell.familyNameLable.text =@"我";
                }
                cell.jumpImgView.hidden = YES;
                cell.addImgButton.userInteractionEnabled = YES;
            }
            //过来的是某个家人
            else
            {
                cell.familyNameLable.text = [NSString stringWithFormat:@"%@(%@)",self.peopleDic[@"realname"],typeDic[self.peopleDic[@"type"]]];
                //本地路径
                NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
                //文件夹地址
                NSString * headerImgFloder = [docPath stringByAppendingString:[NSString stringWithFormat:@"/FamilyHeaderFloder/"]];
                //图片地址
                NSString * newPicPath = [headerImgFloder stringByAppendingString:[NSString stringWithFormat:@"headerImg%@%@.jpg",uid,fid]];
                NSFileManager *fileManager = [NSFileManager defaultManager];
                
                //如果这个文件夹存并且这个图片存在就进行下一步操作
                if ([fileManager fileExistsAtPath:headerImgFloder] && [fileManager fileExistsAtPath:newPicPath]) {
                    UIImage * img = [UIImage imageWithContentsOfFile:newPicPath];
                    if (img != nil) {
                        [cell.familyHeaderImgView setImage:img];
                    }else{
                        [cell.familyHeaderImgView setImageWithURL:[NSURL URLWithString:self.peopleDic[@"avatar"]] placeholderImage:[UIImage imageNamed:@"默认头像"]];
                    }
                    
                }else{
                    [cell.familyHeaderImgView setImageWithURL:[NSURL URLWithString:self.peopleDic[@"avatar"]] placeholderImage:[UIImage imageNamed:@"默认头像"]];
                }
            
                [cell.jumpImgView setImage:[UIImage imageNamed:@"公用_跳转.png"]];
                cell.addImgButton.userInteractionEnabled = NO;
            }
            
            
            return cell;
        }
        else if(indexPath.section == 1)//-----病历
        {
            DrugReminderSecondSectionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Second"];
            if (cell == nil) {
                if (IPhone6Plus) {
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"DrugReminderSecondSectionCell" owner:self options:nil] lastObject];//a20
                }else{
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"DrugReminderSecondSectionCell" owner:self options:nil] firstObject];
                }//a20
            }
            
            [cell.drugJumpImgView setImage:[UIImage imageNamed:@"公用_跳转.png"]];
            cell.drugNameLable.text = @"病历";
            cell.countAndReminderTimeLale.hidden = YES;
            cell.drugJumpImgView.right = kScreenWidth-15;
            if (IPhone6Plus) {
                cell.drugJumpImgView.right = kScreenWidth-20;
            }
            
            return cell;
            
        }else
        {
            DrugReminderSecondSectionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Second"];
            if (cell == nil) {
                if (IPhone6Plus) {
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"DrugReminderSecondSectionCell" owner:self options:nil] lastObject];
                }else{
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"DrugReminderSecondSectionCell" owner:self options:nil] firstObject];
                }
            }
            [cell.drugJumpImgView setImage:[UIImage imageNamed:@"公用_跳转.png"]];
            cell.drugJumpImgView.right = kScreenWidth-15;
           
            
            if (indexPath.row != self.sectionDataArray.count-1)//不等于最后一行
            {
                
                //显示药物提醒--
                FamilyDrugDetialModal * modal = self.sectionDataArray[indexPath.row];
                NSArray * timeArray = [modal.time componentsSeparatedByString:@","];
                cell.drugNameLable.text = modal.drug;
                cell.countAndReminderTimeLale.text = [NSString stringWithFormat:@"%@ %@",modal.dose,timeArray[0]];
                cell.countAndReminderTimeLale.right = cell.drugJumpImgView.left-5;
                
            }else//最后一行
            {
                
                cell.drugNameLable.text = @"添加用药提醒";
                cell.countAndReminderTimeLale.hidden = YES;
                cell.drugJumpImgView.frame = CGRectMake(kScreenWidth-20-15,(cell.height - 20)/2.0, 20, 20);
                [cell.drugJumpImgView setImage:[UIImage imageNamed:@"加号"]];
            }
            if (IPhone6Plus) {
                cell.drugJumpImgView.right = kScreenWidth-20;
                cell.countAndReminderTimeLale.right = cell.drugJumpImgView.left-5;
            }
            
            return cell;
            
            
        }
    }
    else if([self.MedicalRecord isEqualToString:@"没有病历"]){
        if (indexPath.section == 0)
        {
            FamilyInfoFirstSectionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"First"];
            if (cell == nil) {
                if (IPhone6Plus) {
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyInfoFirstSectionCell" owner:self options:nil] lastObject];
                }else{
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyInfoFirstSectionCell" owner:self options:nil] firstObject];
                }
            }
            cell.familyHeaderImgView.clipsToBounds = YES;
            cell.familyHeaderImgView.layer.cornerRadius = 3;
            cell.jumpImgView.right = kScreenWidth-15;
            if (IPhone6Plus) {
                cell.jumpImgView.right = kScreenWidth-20;
            }
            
            NSString * fid = [NSString stringWithFormat:@"%@",self.peopleDic[@"fid"]];
            NSString * uid = [NSString stringWithFormat:@"%@",self.peopleDic[@"uid"]];
            
            
            //uid和fid一样就是“我”
            if ([fid isEqualToString:uid])
            {
                if ([self.peopleDic[@"realname"] length] !=0) {
                    cell.familyNameLable.text =[NSString stringWithFormat:@"我(%@)",self.peopleDic[@"realname"]];
                }else {
                    cell.familyNameLable.text = @"我";
                    
                }
                //头像
                UIImage * userImg = [[UserManager shareInstance] getUserImage];
                if (userImg) {
                    [cell.familyHeaderImgView setImage:userImg];
                }else{
                    [cell.familyHeaderImgView setImage:[UIImage imageNamed:@"默认头像.png"]];
                }
                cell.jumpImgView.hidden = YES;
                cell.addImgButton.userInteractionEnabled = YES;
            }
            else
            {
                cell.familyNameLable.text = [NSString stringWithFormat:@"%@(%@)",self.peopleDic[@"realname"],typeDic[self.peopleDic[@"type"]]];
                //本地路径
                NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
                //文件夹地址
                NSString * headerImgFloder = [docPath stringByAppendingString:[NSString stringWithFormat:@"/FamilyHeaderFloder/"]];
                //图片地址
                NSString * newPicPath = [headerImgFloder stringByAppendingString:[NSString stringWithFormat:@"headerImg%@%@.jpg",uid,fid]];
                NSFileManager *fileManager = [NSFileManager defaultManager];
                
                //如果这个文件夹存并且这个图片存在就进行下一步操作
                if ([fileManager fileExistsAtPath:headerImgFloder] && [fileManager fileExistsAtPath:newPicPath]) {
                    UIImage * img = [UIImage imageWithContentsOfFile:newPicPath];
                    if (img != nil) {
                        [cell.familyHeaderImgView setImage:img];
                    }else{
                        [cell.familyHeaderImgView setImageWithURL:[NSURL URLWithString:self.peopleDic[@"avatar"]] placeholderImage:[UIImage imageNamed:@"默认头像"]];
                    }
                    
                }else{
                    [cell.familyHeaderImgView setImageWithURL:[NSURL URLWithString:self.peopleDic[@"avatar"]] placeholderImage:[UIImage imageNamed:@"默认头像"]];
                }
                
                [cell.jumpImgView setImage:[UIImage imageNamed:@"公用_跳转.png"]];
                cell.addImgButton.userInteractionEnabled = NO;
            }
            
            
            return cell;
        }
        else//第二段--具体药物提醒 + “添加用药提醒”
        {
            DrugReminderSecondSectionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Second"];
            if (cell == nil) {
                if (IPhone6Plus) {
                     cell = [[[NSBundle mainBundle] loadNibNamed:@"DrugReminderSecondSectionCell" owner:self options:nil] lastObject];
                }else{
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"DrugReminderSecondSectionCell" owner:self options:nil] firstObject];
                }
            }
           
            
            [cell.drugJumpImgView setImage:[UIImage imageNamed:@"公用_跳转.png"]];
            
            if (indexPath.row != self.sectionDataArray.count-1)//不等于最后一行
            {
                
                //显示药物提醒--
                FamilyDrugDetialModal * modal = self.sectionDataArray[indexPath.row];
                NSArray * timeArray = [modal.time componentsSeparatedByString:@","];
                cell.drugNameLable.text = modal.drug;
                cell.countAndReminderTimeLale.text = [NSString stringWithFormat:@"%@ %@",modal.dose,timeArray[0]];
                cell.drugJumpImgView.right = kScreenWidth-15;
                cell.countAndReminderTimeLale.right = cell.drugJumpImgView.left-5;
                
            }else//最后一行
            {
                
                cell.drugNameLable.text = @"添加用药提醒";
                cell.countAndReminderTimeLale.hidden = YES;
                cell.drugJumpImgView.frame = CGRectMake(kScreenWidth-20-15,(cell.height - 20)/2.0 , 20, 20);
                [cell.drugJumpImgView setImage:[UIImage imageNamed:@"加号"]];
            }
            if (IPhone6Plus) {
                cell.drugJumpImgView.right = kScreenWidth - 20;
                cell.countAndReminderTimeLale.right = cell.drugJumpImgView.left-5;
            }
            
            
            return cell;
        }
   }
    else{
       return nil;
    }
    
}
#pragma mark ---选中某一行
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.MedicalRecord isEqualToString:@"病历"]) {
        if (indexPath.section == 0)//个人信息
        {
            NSString * fid = [NSString stringWithFormat:@"%@",self.peopleDic[@"fid"]];
            NSString * uid = [NSString stringWithFormat:@"%@",self.peopleDic[@"uid"]];
            if ([fid isEqualToString:uid])//“我”自己就不跳转了
            {
                return;
            }
            else
            {
                ShowMyFamilyDetialViewController * showDetial = [[ShowMyFamilyDetialViewController alloc] init];
                //去家人详情页面
                showDetial.familyAllDetialDic = self.peopleDic;
                
                MyNSLog("%@", self.peopleDic);
                
                [self.navigationController pushViewController:showDetial animated:YES];
            }
            
        }else if (indexPath.section == 1){
            //病历
            //push到病历页面
            MyNSLog("病历");
            FamilyMedicalrecordViewController * medical = [[FamilyMedicalrecordViewController alloc] init];
            MyNSLog("病历---》 %@,%@",self.peopleDic[@"fid"],self.peopleDic[@"uid"] );
            
            if ([self.peopleDic[@"fid"] intValue]== [self.peopleDic[@"uid"] intValue] )//如果是我自己的话就传一个 “0”
            {
                medical.fid = @"0";
                medical.navBarTitleWithFamilyName = @"我的病历";
            }else
            {
                medical.fid = self.peopleDic[@"fid"];
                medical.navBarTitleWithFamilyName = [NSString stringWithFormat:@"%@的病历",self.peopleDic[@"realname"]];
            }
            [self.navigationController pushViewController:medical animated:YES];
            
            
        }
        else
        {
            
            if (indexPath.row == self.sectionDataArray.count - 1)//push到添加药品提醒
            {
                [self addReminderClicked];
            }
            else//push展示药品详情页面-->这是去展示旧有数据
            {
                self.selectedSecondCell = (DrugReminderSecondSectionCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                FamilyDrugDetialModal * modal = self.sectionDataArray[indexPath.row];
                ShowDrugDetialViewController * showDetial = [[ShowDrugDetialViewController alloc] init];
                showDetial.drugName = modal.drug;
                showDetial.doseCountString = modal.dose;
                showDetial.timeString = modal.time;
                
                /*
//                NSString * fid = self.peopleDic[@"fid"];
//                NSString * uid = self.peopleDic[@"uid"];
//                NSString * type = self.peopleDic[@"type"];
//                NSString * avatar = self.peopleDic[@"avatar"];
//                NSString * realname = self.peopleDic[@"realname"];
//                NSString * username = self.peopleDic[@"username"];
//                showDetial.familyInfoDic = @{@"fid":fid,@"uid":uid,@"realname":realname,@"username":username,@"reminderID":modal.reminderId,@"type":type,@"avatar":avatar};

                 */
                
                NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithCapacity:0];
                [dic setDictionary:self.peopleDic];
                [dic setValue:modal.reminderId forKey:@"reminderID"];
                
                showDetial.familyInfoDic = dic;
                [self.navigationController pushViewController:showDetial animated:YES];
            }
        }
    }
    if([self.MedicalRecord isEqualToString:@"没有病历"]){
        if (indexPath.section == 0)//个人信息
        {
            NSString * fid = [NSString stringWithFormat:@"%@",self.peopleDic[@"fid"]];
            NSString * uid = [NSString stringWithFormat:@"%@",self.peopleDic[@"uid"]];
            if ([fid isEqualToString:uid])//“我”自己就不跳转了
            {
                return;
            }
            else
            {
                ShowMyFamilyDetialViewController * showDetial = [[ShowMyFamilyDetialViewController alloc] init];
                //去家人详情页面
                MyNSLog("%@", self.peopleDic);
                if (self.isPresent) {
                    showDetial.isPresent = YES;
                }

                showDetial.familyAllDetialDic = self.peopleDic;
                
                [self.navigationController pushViewController:showDetial animated:YES];
            }
            
        }
        else//点击第二段的cell
        {
            if (indexPath.row == self.sectionDataArray.count - 1)//push到添加药品提醒
            {
                [self addReminderClicked];
            }
            else//push展示药品详情页面-->这是去展示旧有数据
            {
                self.selectedSecondCell = (DrugReminderSecondSectionCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                FamilyDrugDetialModal * modal = self.sectionDataArray[indexPath.row];
                ShowDrugDetialViewController * showDetial = [[ShowDrugDetialViewController alloc] init];
                showDetial.drugName = modal.drug;
                showDetial.doseCountString = modal.dose;
                showDetial.timeString = modal.time;
//                NSString * fid = self.peopleDic[@"fid"];
//                NSString * uid = self.peopleDic[@"uid"];
//                NSString * realname = self.peopleDic[@"realname"];
//                NSString * username = self.peopleDic[@"username"];
//                NSString * type = self.peopleDic[@"type"];
//                NSString * avatar = self.peopleDic[@"avatar"];
//                showDetial.familyInfoDic = @{@"fid":fid,@"uid":uid,@"realname":realname,@"username":username,@"reminderID":modal.reminderId,@"type":type,@"avatar":avatar};
                NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithCapacity:0];
                [dic setDictionary:self.peopleDic];
                [dic setValue:modal.reminderId forKey:@"reminderID"];
            
                showDetial.familyInfoDic = dic;
                [self.navigationController pushViewController:showDetial animated:YES];
            }
        }
    }

    
}
//添加--》push 到添加页面
-(void)addReminderClicked
{
    AddDrugReminderViewController * addReminder = [[AddDrugReminderViewController alloc] init];
//    NSString * fid = self.peopleDic[@"fid"];
//    NSString * uid = self.peopleDic[@"uid"];
//    NSString * realname = self.peopleDic[@"realname"];
//    NSString * username = self.peopleDic[@"username"];
//    NSString * type = self.peopleDic[@"type"];
//    
//    addReminder.familyInfoDic = @{@"fid":fid,@"uid":uid,@"realname":realname,@"username":username,@"type":type};
    addReminder.familyInfoDic = self.peopleDic;
    [self.navigationController pushViewController:addReminder animated:YES];
    
}
@end
